<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('岗位新增')"/>
</head>
<body>
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">单位名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="deptName" lay-verify="deptName" autocomplete="off" placeholder="单位名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">单位地址</label>
                    <div class="layui-input-block">
                        <input  name="deptAddress"  autocomplete="off" placeholder="单位地址"  class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">单位邮编</label>
                    <div class="layui-input-block">
                        <input type="text" name="deptZip"  autocomplete="off" placeholder="单位邮编" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">银行卡号</label>
                    <div class="layui-input-block">
                        <input type="text" name="bankAccount" lay-verify="bankAccount" autocomplete="off" placeholder="银行卡号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">立项号段</label>
                    <div class="layui-input-block">
                        <input type="text" name="applyNumber"  autocomplete="off" placeholder="号段格式为:xxx-xxx,例如“20001-20080”" class="layui-input">
                    </div>
                </div>

<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-form-label">状态</label>-->
<!--                    <div class="layui-input-block">-->
<!--                        <select id="status" name="status">-->
<!--                            <option value="1">开启</option>-->
<!--                            <option value="0">关闭</option>-->
<!--                        </select>-->
<!--                    </div>-->
<!--                </div>-->

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="position-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let MODULE_PATH = rootPath+"/SysPositionController";
        //名称验证
        form.verify({
            username: function(value){
                if(value.length < 2){
                    return '至少得2个字符';
                }
                var msg = "";
                $.ajax({
                    url: MODULE_PATH+'/checkNameUnique',
                    data: "postName="+value,
                    dataType: 'json',
                    type: 'post',
                    async:false,
                    success: function (result) {
                            msg=result;
                    }
                });
                if (msg == 1) {
                   return "已有相同数据";
                }

            },
            // applyNumber: function (value){
            //     var format = /^([1-9])+-([1-9])+$/;
            //     if(!format.test(value))
            //     {
            //         return '请输入正确的号段格式！';
            //     }
            // },
            bankAccount: function (value){
                if($("#deptName").val()!="群众"){
                    var format =  /^(\d{16}|\d{19}|\d{17})$/;
                    if(!format.test(value))
                    {
                        return '请输入正确的银行卡号！';
                    }
                }
            }
        });



        //保存
        form.on('submit(position-save)', function (data) {
            $.ajax({
                url: MODULE_PATH+'/add',
                data: data.field,
                dataType: 'json',
                contentType: 'application/x-www-form-urlencoded',
                type: 'post',
                success: function (result) {
                    if (result.code==200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("position-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>